//
//  SurroundingView.m
//  Movie
//
//  Created by 路贵斌 on 15/11/4.
//  Copyright © 2015年 huazi. All rights reserved.
//

#import "SurroundingView.h"

#import "CustomScrollView.h"
#import "HYCustomSegementView.h"

#import "SurroundingCell.h"

@interface SurroundingView ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView       *tableView;
@property (nonatomic, strong) NSMutableArray    *dataSource;

@end

@implementation SurroundingView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)initUI
{
    [self initTableView];
}

- (void)initTableView
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.tableFooterView = [UIView new];
    self.tableView.tableHeaderView = [[NSBundle mainBundle]loadNibNamed:@"CustomScrollView" owner:self options:nil][0];

    [self addSubview:self.tableView];
    
    //registerCell
    [self.tableView registerNib:[UINib nibWithNibName:@"SurroundingCell" bundle:nil] forCellReuseIdentifier:@"SurroundingCell"];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SurroundingCell * cell  = [tableView dequeueReusableCellWithIdentifier:@"SurroundingCell"];
    [cell resetCellWithEntity:nil];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44.0;
}

- (void)startRequest {
    [MBProgressHUD showHUDAddedTo:self animated:YES];
    NSDictionary *dicParams =@{};  //请求需要的参数
    HZMRequest *request =[[HZMRequest alloc] init];
    request.requsetId =kASXcompare;
    request.requestParamDic =dicParams;
    request.callBackDelegate =self;
    [[HZMAPImanager shareMAPImanager] getWithWSRequest:request];   //get  or Post
}


#pragma mark--HZMAPIManagerDelegate
- (void)transactionFinished:(HZMResponse *)response
{
    [MBProgressHUD hideHUDForView:self animated:YES];
    
    if ([response.requestId isEqualToString:kASXcompare])
    {
//        self.dataSource = [HotMovieCellEntity mj_objectArrayWithKeyValuesArray:response.responseData[@"body"][@"content"][@"compare"]];
//        
//        self.topHotMovieArray = [HotMovieCellEntity mj_objectArrayWithKeyValuesArray:response.responseData[@"body"][@"content"][@"hotMovie"]];
        
        //[(CustomScrollView *)self.tableView.tableHeaderView resetScrollViewWithArray:self.topHotMovieArray];
        
        [self.tableView reloadData];
        
    }
    else {
        [self makeToast:response.responseMsg duration:1.0 position:@"center"];
    }
    
}
- (void)transactionFailed:(HZMResponse *)response
{
    [MBProgressHUD hideHUDForView:self animated:YES];
    [self makeToast:response.responseMsg duration:1.0 position:@"center"];
}

@end
